package com.octnote.controller;

import com.octnote.domain.AppCfgParamFrom;
import com.octnote.domain.News;
import com.octnote.domain.NewsCreateForm;
import com.octnote.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by leohehe on 2017/6/23.
 */
@RestController
@RequestMapping(value = "/api/v1/", name = "系统设置API")
public class AppConfigController {
    private static final Logger LOGGER = LoggerFactory.getLogger(AppConfigController.class);
    private Message message = new Message();

    @ResponseBody
    @RequestMapping(value = "i/appcfg/update", method = RequestMethod.POST)
    public ResponseEntity<Message> updateAppCfg(@Valid @RequestBody AppCfgParamFrom form) {
        try {
            message.setMsg(1, "更新系统设置成功");
            return new ResponseEntity<Message>(message, HttpStatus.OK);
        } catch (DataIntegrityViolationException e) {
            LOGGER.warn("create news error", e);
            message.setMsg(0, "更新系统设置失败");
            return new ResponseEntity<Message>(message, HttpStatus.OK);
        }
    }
}
